﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TGVR.Manager.UserControls.Template.MessageBox
{
    public partial class MessageBox : System.Web.UI.UserControl
    {
        #region data member
        public MessageBoxClassType msgType 
        { 
            get
            {
                return (MessageBoxClassType)ViewState["SMBCNBMsgBox"];
            }
            set
            {
                ViewState["SMBCNBMsgBox"] = value;
            }
        }

        public delegate void btnMsgDelegate();
        public btnMsgDelegate btnMsgOkClick
        {
            get { return (btnMsgDelegate)Session["btnMsgOkClickHandler"]; }
            set { Session["btnMsgOkClickHandler"] = value; }
        }

        public btnMsgDelegate btnMsgCancelClick
        {
            get { return (btnMsgDelegate)Session["btnMsgCancelClickHandler"]; }
            set { Session["btnMsgCancelClickHandler"] = value; }
        }
        #endregion

        #region contructor
        public MessageBox()
        {
            if(this.msgType == null)
                this.msgType = new MessageBoxClassType();
        }
        #endregion

        #region methods
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        public void ShowInfo(string content, string title = "Thông báo", btnMsgDelegate okHanler = null)
        {
            this.msgType.SetInfoClass();
            btnMsgCancel.Visible = false;
            lblTitle.Text = title;
            ltrContent.Text = content;
            msgboxcontainerscreen.Visible = true;
            btnMsgOkClick = okHanler;
        }

        public void ShowSuccessful(string content, string title = "Thông báo", btnMsgDelegate okHanler = null)
        {
            this.msgType.SetSuccessClass();
            btnMsgCancel.Visible = false;
            lblTitle.Text = title;
            ltrContent.Text = content;
            msgboxcontainerscreen.Visible = true;
            btnMsgOkClick = okHanler;
        }

        public void ShowWarning(string content, string title = "Cảnh báo", btnMsgDelegate okHanler = null)
        {
            this.msgType.SetWarningClass();
            btnMsgCancel.Visible = false;
            lblTitle.Text = title;
            ltrContent.Text = content;
            msgboxcontainerscreen.Visible = true;
            btnMsgOkClick = okHanler;
        }

        public void ShowError(string content, string title = "Lỗi", btnMsgDelegate okHanler = null)
        {
            this.msgType.SetErrorClass();
            btnMsgCancel.Visible = false;
            lblTitle.Text = title;
            ltrContent.Text = content;
            msgboxcontainerscreen.Visible = true;
            btnMsgOkClick = okHanler;
        }

        protected void btnMsgOk_Click(object sender, EventArgs e)
        {
            if (btnMsgOkClick != null)
            {
                btnMsgOkClick();
            }
            msgboxcontainerscreen.Visible = false;
        }

        protected void btnMsgCancel_Click(object sender, EventArgs e)
        {
            if(btnMsgCancelClick != null)
            {
                btnMsgCancelClick();
            }
            msgboxcontainerscreen.Visible = false;
        }
        #endregion
    }

    [Serializable]
    public class MessageBoxClassType
    {
        public string backgroundClass { get; set; }
        public string iconClass { get; set; }

        public MessageBoxClassType()
        {
            this.backgroundClass = "msginfo";
            this.iconClass = "fa-bell";
        }

        public void SetInfoClass()
        {
            this.backgroundClass = "msginfo";
            this.iconClass = "fa-bell";
        }
        public void SetSuccessClass()
        {
            this.backgroundClass = "msgsuccessful";
            this.iconClass = "fa-check";
        }
        public void SetWarningClass()
        {
            this.backgroundClass = "msgwarning";
            this.iconClass = "fa-shield";
        }
        public void SetErrorClass()
        {
            this.backgroundClass = "msgerror";
            this.iconClass = "fa-warning";
        }
    }
}